/*
 * @Description: table组件声明
 * @Author: seadon
 * @LastEditors: seadon
 * @Date: 2021-03-29 09:57:50
 * @LastEditTime: 2021-08-02 09:53:07
 */
import { ColumnType } from 'ant-design-vue/lib/table/interface'
import { VueNode } from '@/types/type'
import { PaginationProps } from './pagination'

export declare type SortOrder = 'ascend' | 'descend'
export type SizeType = 'default' | 'middle' | 'small'

// support component
export type ComponentType = 'Input' | 'Select' | 'Checkbox' | 'Switch'

export interface BasicColumn extends ColumnType {
	children?: BasicColumn[]
	customTitle?: VueNode
	customTitleSelect?: string | number
	// Editable
	edit?: boolean
	editRow?: boolean
	editable?: boolean
	editComponent?: ComponentType
	editComponentProps?: Recordable
	editRule?: boolean | ((text: string, record: Recordable) => Promise<string>)
	editValueMap?: (value: any) => string
	onEditRow?: () => void
}

/**
 * 表格Api
 */
export interface BasicTableProps<T = any> {
	// 展示列对象
	columns: BasicColumn[]
	// 行主键
	rowKey?: string | ((record: Recordable) => string)
	// 数据源
	dataSource?: Recordable[]
	// 表格大小
	size?: SizeType
	// 是否显示边框
	bordered?: boolean
	// 分页配置
	pagination?: PaginationProps | boolean
	// loading加载
	loading?: boolean
	// 设置滚动
	scroll?: { x?: number | string | true; y?: number | string }
	// 额外的请求参数
	searchInfo?: Recordable
	// 设置行属性
	customRow?: (record: T, index: number) => object
	// 表格编辑事件
	onEditChange?: Fn
	onEditEnd: Fn
	onEditCancel: Fn
	onEditRowEnd: Fn
}

// 列表操作类型
export interface TableActionType {
	updateTableData: (index: number, key: string, value: any) => Recordable
	emit?: EmitType
}

/**
 * 自定义渲染行参数
 */
export interface Params {
	text: string
	record: Recordable
	index: number
}

/**
 * 排序结果
 */
export interface SorterResult {
	column: ColumnType
	order: SortOrder
	field: string
	columnKey: string
}

/**
 * 自定义列选择项
 */
export interface CheckedItem {
	checkedList: string[]
	defaultCheckList: string[]
}
